package com.bian.controller;
import com.bian.Userdao.Userdaoimpl;
import com.bian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

    @Autowired
    private Userdaoimpl userdaoimpl;
        @RequestMapping("/user")
        public String User(User user, Model model, HttpServletRequest request ){
            User user1;
            try {
                user1 = userdaoimpl.findUser(user);
            }catch (Exception e){
                user1=null;
            }
            // 登录成功跳转 不成功提示
            if (user1==null) {
               request.getSession().setAttribute("msg","账号或密码错误！");
                return "redirect:/";
            }else {
                model.addAttribute("user",user.getUsername());
                request.getSession().setAttribute("user",user.getUsername());
                return "user";
            }

        }
}
